// pages/seckillPage/main.js
import { formatNumber} from '../../utils/util.js'
Page({
  
  /**
   * 页面的初始数据
   */
  data: {
    hour:0,
    tab:[
      {
        txt: '最后疯抢',
        desc:'已开抢',
        id: 0,
        isActive: false
      },
      {
        txt: '',
        desc:'抢购中',
        id: 1,
        isActive: true
      },
      {
        txt: '',
        desc:'即将开抢',
        id: 2,
        isActive: false
      },
      {
        txt: '',
        desc:'即将开抢',
        id: 3,
        isActive: false
      },
      {
        txt: '',
        desc:'即将开抢',
        id: 4,
        isActive: false
      },
      {
        txt: '',
        desc:'即将开抢',
        id: 5,
        isActive: false
      },
    ],
  },
  handleTab(e){
    const {index} = e.detail;
    let {tab} = this.data;
    tab.forEach((v,i) => {i===index?v.isActive=true:v.isActive=false})
    this.setData({
      tab
    })
  },
  getTime(){
    let timeId=setInterval(() => {
      let time = new Date();
      let year = time.getFullYear();
      let month = time.getMonth();
      let day = time.getDate();
      let hour = time.getHours();
      hour = Math.floor(hour/2)*2;
      var time2 = new Date(year+'/'+(month+1)+'/'+day+' '+(hour+2)+':00')
      let des = time2.getTime()-time.getTime()
      let time3 = new Date(des)
      let remaintime = formatNumber(time3.getHours()-8)+':'+formatNumber(time3.getMinutes())+':'+formatNumber(time3.getSeconds())
      this.setData({
        hour,
        remaintime
      })
    }, 1000);
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getTime()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})